#!/bin/bash

#
# (c) 2009 Mandriva, http://www.mandriva.com/
# (c) 2009 Jean-Dominique Frattini, jd.frattini@free.fr
#
# $Id: $
#
# This file is part of ATS (Automated Testing System), 
# http://http://wiki.mandriva.com/en/Automated_testing_system
#
# ATS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# ATS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pulse 2; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

# usage: ./uninstall.sh

# this file has to be run once on the virtual machine in order to uninstall 
# the Test-Cloud guest client programs.

if ! test -f /etc/testcloud-testrunner/install
then
   echo "testcloud-testrunner seems already uninstalled."
   exit 0
fi

while read line
do
   install_dir=$line
   read pkg_name
   read user_name
done < "/etc/testcloud-testrunner/install"

if [ "$pkg_name" = "" ]
then
   echo "Uninstallation cannot continue, aborting !"
   exit 1
fi

if [ "$install_dir" = "" ]
then
   echo "Uninstallation cannot continue, aborting !"
   exit 2
fi

rm -fr /etc/$pkg_name
rm -fr /var/log/$pkg_name
rm -fr /usr/share/$pkg_name
rm -fr $install_dir/share/doc/$pkg_name
rm -f $install_dir/bin/annotate-output.sh
rm -f $install_dir/bin/testcloud-testrunner.sh
rm -f $install_dir/bin/timered-sh.sh
rm -f $install_dir/bin/testcloud-vm-halt.sh

echo "testcloud-testrunner was succesfully uninstalled if no error were printed on screen."
